﻿@{
    ViewBag.Title = "网站管理平台_新建专家";
}

@section HeadContent
{
    <script type="text/javascript">
        var initCataId = function (combo) {
            var selCataId = App.ExpCataId.getValue();
            var index = 0;
            if (selCataId != 0) {
                var store = combo.getStore();
                Ext.each(store.data.keys, function (value) {
                    if (value == selCataId) {
                        combo.select(store.getAt(index));
                        return false;
                    }
                    else {
                        index++;
                    }
                });
            }
        };

        var onSubmitSuccess = function (response, data) {
            Ext.Msg.show({ title: '提示', msg: data.extraParams.Msg, buttons: Ext.Msg.OK, icon: Ext.Msg.INFO, modal: true,
                fn: function (btn) {
                    var iview = window.parent.App.ImageView;
                    if (iview != null) {
                        iview.getStore().reload();
                    }
                    var wnd = window.parent.App.Window1;
                    if (wnd != null) {
                        wnd.close();
                    }
                }
            });
        }
    </script>
}

@Html.X().Hidden().ID("ExpCataId").Text(ViewData["ExpCataID"].ToString())

@(Html.X().Viewport()
    .Layout("fit")
    .Items(
            Html.X().FormPanel()
                .ID("FormPanel1")
                .Layout("Column")
                .AutoScroll(true)
                .Items(
                    Html.X().Panel()
                        .Border(false)
                        .ColumnWidth(0.5)
                        .Padding(5)
                        .Layout("form")
                        .Defaults(
                            Html.X().Parameter().Name("AnchorHorizontal").Value("90%")
                        )
                        .Items(
                                Html.X().TextField().ID("ExpertName").FieldLabel("专家姓名").AllowBlank(false).MaxLength(20),
                                Html.X().ComboBox().ID("ExpertCataID").FieldLabel("所属专家目录").Editable(false).AllowBlank(false)
                                    //.StoreID("Store1")
                                    .Store(Html.X().Store()
                                        .Control(c => { c.Data = ViewData["ExpCata"]; })
                                        .Model(Html.X().Model().IDProperty("ExpertCataID")
                                            .Fields(
                                                    new ModelField("ExpertCataID", ModelFieldType.Int),
                                                    new ModelField("ExpertCataName")
                                            )
                                        )
                                        //.Proxy(Html.X().AjaxProxy().Url(Url.Action("GetAllExpertByCata", "ExpertCata")).Reader(Html.X().JsonReader().Root("data")))
                                    )
                                    .DisplayField("ExpertCataName")
                                    .ValueField("ExpertCataID")
                                    .Listeners(ls =>
                                    {
                                        ls.Render.Fn = "initCataId";
                                    }),
                                Html.X().TextField().ID("ExpertPosition").FieldLabel("专家职位").MaxLength(20)

                        ),
                    Html.X().Panel()
                        .Border(false)
                        .ColumnWidth(0.5)
                        .Padding(5)
                        .Layout("form")
                        .Defaults(
                            Html.X().Parameter().Name("AnchorHorizontal").Value("90%")
                        )
                        .Items(
                                 Html.X().TextField().ID("ExpertJob").FieldLabel("专家职称").MaxLength(20),
                            Html.X().NumberField().ID("SortNum").FieldLabel("排序序号").MinValue(0),
                            Html.X().ComboBox().ID("IsShow").FieldLabel("是否显示").Editable(false)
                                .Items(
                                    Html.X().ListItem().Text("隐藏").Value("0"),
                                    Html.X().ListItem().Text("显示").Value("1")
                                ).SelectedItems("1")
                            )
                            ,
                                Html.X().Panel()
                            .Border(false)
                            .Padding(5)
                            .Layout(LayoutType.Form)
                            .ColumnWidth(1)
                            .Defaults(
                                Html.X().Parameter().Name("AnchorHorizontal").Value("90%")
                            )
                            .Items(
                                     Html.X().FileUploadField().ID("ExpertPic").FieldLabel("专家头像").Icon(Icon.ImageAdd).ButtonText("").AllowBlank(false),
                                            Html.X().HtmlEditor().ID("Introduction").FieldLabel("个人简介").Height(200),
                                                 Html.X().HtmlEditor().ID("SkillField").FieldLabel("技能领域").Height(150),
                                             Html.X().HtmlEditor().ID("Achievement").FieldLabel("主要成就").Height(200),
                                                          Html.X().HtmlEditor().ID("OtherMsg").FieldLabel("其他补充信息").Height(200)
                            )
                )
                .TopBar(
                    Html.X().Toolbar().Items(
                        Html.X().Button().Text("保存").Icon(Icon.Disk)
                            .DirectEvents(de =>
                            {
                                de.Click.Action = "CreateExperts";
                                de.Click.EventMask.ShowMask = true;
                                de.Click.EventMask.Msg = "正在保存";
                                de.Click.Success = "onSubmitSuccess";
                                de.Click.Failure = "ext.net.comjs.onSubmitFailure";
                                de.Click.IsUpload = true;
                            })
                               .Listeners(ls =>
                               {
                                   ls.Click.Handler = "return ext.net.comjs.onFormSubmit()";
                               })
                    )
                )
                .BottomBar(Html.X().StatusBar().DefaultText("Ready"))
                        .Listeners(ls => ls.ValidityChange.Handler = "ext.net.comjs.setFormStatusBar(this, valid)")


    )
)
